//
//  MLAHomeCell.m
//  MagicLampApp
//
//  Created by Zheng on 2018/12/19.
//  Copyright © 2018 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAHomeCell.h"
#import "MLANewsModel.h"

@implementation MLAHomeCell {
    UIImageView *newsImgv;
    UILabel *titleLbl;
    UILabel *dateLbl;
}


- (void)setModel:(MLANewsModel *)model {
    _model = model;
    
    [newsImgv sd_setImageWithURL:[NSURL URLWithString:_model.pic]];
    dateLbl.text = _model.ctime;
    titleLbl.text = _model.synopsis;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        newsImgv = [[UIImageView alloc] init];
        newsImgv.layer.cornerRadius = 5;
        newsImgv.layer.masksToBounds = YES;
        [self.contentView addSubview:newsImgv];
        [newsImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(85);
            make.height.mas_equalTo(48);
            make.left.mas_equalTo(15);
            make.centerY.equalTo(self);
        }];
        
        dateLbl = [[UILabel alloc] init];
        dateLbl.font = CX_GetNormalFont(10);
        dateLbl.textColor = CX_GetColorHex(0x999999, 1);
        [self.contentView addSubview:dateLbl];
        [dateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.centerY.equalTo(self);
        }];
        
        titleLbl = [[UILabel alloc] init];
        titleLbl.font = CX_GetNormalFont(12);
        titleLbl.textColor = CX_GetColorSubTitle();
        titleLbl.numberOfLines = 2;
        [self.contentView addSubview:titleLbl];
        [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self->newsImgv.mas_right).offset(10);
            make.right.equalTo(self->dateLbl.mas_left).offset(-36);
            make.centerY.equalTo(self);
        }];
        
        /*
         测试数据
         newsImgv.backgroundColor = CX_GetColorRandom();
         titleLbl.text = @"好心情抹茶- 从宇治到京都到 伦敦市场";
         dateLbl.text = @"2019-09-09";
         */
    }
    return self;
}

@end
